<?php
/**
 * Created by YuanPan.
 * User: YuanPan
 * Date: 2018/5/12
 * Time: 19:14
 */


//tkoen随机字符串
function getRandChar($length)
{
    $str = null;
    $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
    //获取当前字符串长度并减1
    $max = strlen($strPol) - 1;
    //随机累加
    for ($i = 0; $i < $length; $i++)
    {
        $str .= $strPol[rand(0, $max)];
    }
    return $str;
}

/**
 * @param string $url get请求地址
 * @param int $httpCode 返回状态码
 * @return mixed
 */
function curl_get($url, &$httpCode = 0)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //不做证书校验,部署在linux环境下请改为true
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    $file_contents = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $file_contents;
}

/**
 * 模拟post请求，测试支付
 */
function curl_post_raw($url, $rawData)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //不做证书校验,部署在linux环境下请改为true
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $rawData);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type:text'));
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

//隐藏数组中的字段
function hiddenArray($array,$hidden)
{
    if(empty($array)) return $array;
    foreach ($array as $key => $value){
        if(in_array($key,$hidden)){
            continue;
        }
        $result[$key] = $value;
    }
    return $result;
}

//显示数组中的字段
function visibleArray($array,$visible)
{
    if(empty($array)) return $array;
    foreach ($array as $key => $value){
        if(in_array($key,$visible)){
            $result[$key] = $value;
        }
    }
    return $result;
}
//剥开数组 $field 为要剥开的数组名称
function skinArray($array,$field)
{
    if(empty($array)) return $array;
    foreach ($array as $key => $value){
        if($key == $field){
            continue;
        }
        $result[$key] = $value;

    }
    foreach ($array[$field] as $k => $v){
        $result[$k] = $v;
    }

    return $result;
}

function getTodayCount(){
    $timeInfo = getdate(time());
    $map['year'] = $timeInfo['year'];
    $map['mon'] = $timeInfo['mon'];
    $map['day'] = $timeInfo['mday'];
    return $map;
}